import { globalurls } from "/urls.js";
const network = {

  getSearch: function (params) {
    var w = params.w;
    var url = globalurls.searchUrl(w);
    wx.request({
      url: url,
      success: function (res) {
        var songs = res.data.result.songs;
        if (params.success) {
          params.success(songs);
        }
      }
    })
  },
  getDetail: function (params) {
    var id = params.id;
    var url = globalurls.detailUrl(id);
    wx.request({
      url: url,
      success: function (res) {
        var song = res.data.songs[0]
        if (params.success) {
          params.success(song);
        }
      }
    })
  },
  getPlay: function (params) {
    var id = params.id;
    var url = globalurls.playUrl(id);
    wx.request({
      url: url,
      success: function (res) {
        var url = res.data.data[0].url
        if (params.success) {
          params.success(url);
        }
      }
    })
  },
  getComment: function (params) {
    var id = params.id;
    var url = globalurls.commentUrl(id);
    wx.request({
      url: url,
      success: function (res) {
        var comment=res.data
        if (params.success) {
          params.success(comment);
        }
      }
    })
  },
  getLyric: function (params) {
    var id = params.id;
    var url = globalurls.lyricUrl(id);
    wx.request({
      url: url,
      success: function (res) {
        if (res.data.lrc){
          var lrc = res.data.lrc.lyric
        } else  {
          var lrc ="无歌词"          
        }
        if (params.success) {
          params.success(lrc);
        }
      },
    })
  },
  getDetail_search: function (params) {
    var w = params.w;
    var url = globalurls.detail_searchUrl(w);
    wx.request({
      url: url,
      success: function (res) {
        var data = res.data.result
        if (params.success) {
          params.success(data);
        }
      }
    })
  },

  getAll_search: function (params) {
    var w = params.w
    var url = globalurls.all_searchUrl(w);
    wx.request({
      url: url,
      success: function (res) {
        var data = res.data.result
        if (params.success) {
          params.success(data);
        }
      }
    })
  },
}

export { network }